package com.asl.website.contactInfo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.asl.website.contactInfo.domain.SysContactInfoDTO;
import com.asl.website.sysJoinMain.domain.JoinUsDTO;
import com.asl.website.sysJoinMain.domain.SysJoinMain;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.asl.common.annotation.Log;
import com.asl.common.core.controller.BaseController;
import com.asl.common.core.domain.AjaxResult;
import com.asl.common.enums.BusinessType;
import com.asl.website.contactInfo.domain.SysContactInfo;
import com.asl.website.contactInfo.service.ISysContactInfoService;
import com.asl.common.utils.poi.ExcelUtil;
import com.asl.common.core.page.TableDataInfo;

/**
 * 联系信息Controller
 * 
 * @author ruoyi
 * @date 2025-05-21
 */
@RestController
@RequestMapping("/contactInfo/contactInfo")
public class SysContactInfoController extends BaseController
{
    @Autowired
    private ISysContactInfoService sysContactInfoService;
    @GetMapping("/content")
    public AjaxResult getJoinUsContentV2(@RequestHeader(value = "Accept-Language", defaultValue = "zh-CN") String acceptLanguage) {
        List<SysContactInfo> contents = sysContactInfoService.selectSysContactInfoList(new SysContactInfo());
        if (contents.isEmpty()) {
            return AjaxResult.error("未配置页面内容");
        }

        return AjaxResult.success(new SysContactInfoDTO(contents.get(0), acceptLanguage));
    }
    /**
     * 查询联系信息列表
     */
    @PreAuthorize("@ss.hasPermi('contactInfo:contactInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysContactInfo sysContactInfo)
    {
        startPage();
        List<SysContactInfo> list = sysContactInfoService.selectSysContactInfoList(sysContactInfo);
        return getDataTable(list);
    }

    /**
     * 导出联系信息列表
     */
    @PreAuthorize("@ss.hasPermi('contactInfo:contactInfo:export')")
    @Log(title = "联系信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysContactInfo sysContactInfo)
    {
        List<SysContactInfo> list = sysContactInfoService.selectSysContactInfoList(sysContactInfo);
        ExcelUtil<SysContactInfo> util = new ExcelUtil<SysContactInfo>(SysContactInfo.class);
        util.exportExcel(response, list, "联系信息数据");
    }

    /**
     * 获取联系信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('contactInfo:contactInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysContactInfoService.selectSysContactInfoById(id));
    }

    /**
     * 新增联系信息
     */
    @PreAuthorize("@ss.hasPermi('contactInfo:contactInfo:add')")
    @Log(title = "联系信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysContactInfo sysContactInfo)
    {
        return toAjax(sysContactInfoService.insertSysContactInfo(sysContactInfo));
    }

    /**
     * 修改联系信息
     */
    @PreAuthorize("@ss.hasPermi('contactInfo:contactInfo:edit')")
    @Log(title = "联系信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysContactInfo sysContactInfo)
    {
        return toAjax(sysContactInfoService.updateSysContactInfo(sysContactInfo));
    }

    /**
     * 删除联系信息
     */
    @PreAuthorize("@ss.hasPermi('contactInfo:contactInfo:remove')")
    @Log(title = "联系信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysContactInfoService.deleteSysContactInfoByIds(ids));
    }
}
